package ch.usi.inf.pf2.gui.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import ch.usi.inf.pf2.editor.Cut;
import ch.usi.inf.pf2.editor.MultipleCut;
import ch.usi.inf.pf2.gui.JSpreadSheetGUI;
import ch.usi.inf.pf2.gui.SpreadSheetTableModel;

/**
 * 
 * @author Lorenzo Baracchi <lorenzo.baracchi@usi.ch>, Ebrisa Savina
 *         Mastrodicasa
 * 
 */

public class CutActionListener implements ActionListener
{
    private JSpreadSheetGUI spreadTable;

    public CutActionListener(JSpreadSheetGUI spreadTable)
    {
	   this.spreadTable = spreadTable;
    }

    @Override
    public void actionPerformed(ActionEvent e)
    {
		  MultipleCut cut = new MultipleCut(spreadTable.getSheet(),
				spreadTable.getSelectedRows(), spreadTable
					   .getSelectedColumns());
		  cut.evaluate();
		  spreadTable.getStack().addActionToUndoStack(cut);
		  SpreadSheetTableModel tb = (SpreadSheetTableModel) spreadTable
				.getTable().getModel();
		  tb.fireTableCellUpdated(spreadTable.getSelectedRow() + 1,
				spreadTable.getSelectedColumn() + 1);
		  spreadTable.getTable().repaint();
		  spreadTable.getSheet().setHasBeenSaved(false);
    }

}
